package start.spring.basic.job.service.jobmonitor.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import start.spring.basic.constant.CommonConstant;
import start.spring.basic.job.dao.GgThreadExecMapper;
import start.spring.basic.job.entity.GgThreadExec;
import start.spring.basic.job.service.BaseServiceImpl;
import start.spring.basic.job.service.jobmonitor.IGgThreadExecService;
import start.spring.basic.page.PageQuery;
import start.spring.basic.page.PageResult;
import start.spring.basic.util.common.StringUtil;

/**
 * 线程运行记录Service业务层处理
 * 
 * @author xuyy
 * @date 2023-06-29
 */
@Service
public class GgThreadExecServiceImpl extends BaseServiceImpl implements IGgThreadExecService {
    
    @Autowired
    private GgThreadExecMapper ggThreadExecMapper;

    /**
     * 查询线程运行记录列表
     * 
     * @param ggThreadExec 线程运行记录
     * @return 线程运行记录
     */
    @Override
    public PageResult<GgThreadExec> selectGgThreadExecPageList(PageQuery pageQuery,GgThreadExec ggThreadExec) {
        IPage<GgThreadExec> page = super.getPage(pageQuery);
        QueryWrapper<GgThreadExec> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ggThreadExec.getPch()!=null, GgThreadExec::getPch, ggThreadExec.getPch());
        queryWrapper.lambda().like(!StringUtil.isEmpty(ggThreadExec.getThreadname()), GgThreadExec::getThreadname, ggThreadExec.getThreadname());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggThreadExec.getStatus()), GgThreadExec::getStatus, ggThreadExec.getStatus());
        if(!StringUtil.isEmpty(ggThreadExec.getBeginKssj()) && !StringUtil.isEmpty(ggThreadExec.getEndKssj())) {
        	queryWrapper.lambda().between(GgThreadExec::getKssj, ggThreadExec.getBeginKssj() + CommonConstant.SURFIX_DATE_BEGIN, ggThreadExec.getEndKssj() + CommonConstant.SURFIX_DATE_END);
        }
        queryWrapper.lambda().orderByDesc(GgThreadExec::getKssj);
        page = this.ggThreadExecMapper.selectPage(page, queryWrapper);
        return super.getPageResult(page);
    }
    
}
